import { request } from '../../utils/request'
import type { Menu, ApiResponse } from '../../types/app.d'

/**
 * 获取菜单列表
 */
export const getMenuList = (params?: {
  status?: number
  name?: string
  type?: number
}) => {
  return request.get<ApiResponse<Menu[]>>('/system/menu/list', { params })
}

/**
 * 获取菜单详情
 */
export const getMenuInfo = (id: string) => {
  return request.get<ApiResponse<Menu>>(`/system/menu/${id}`)
}

/**
 * 创建菜单
 */
export const createMenu = (data: Omit<Menu, 'id' | 'createTime' | 'updateTime' | 'children'>) => {
  return request.post<ApiResponse>('/system/menu', data)
}

/**
 * 更新菜单
 */
export const updateMenu = (id: string, data: Partial<Omit<Menu, 'id' | 'createTime' | 'children'>>) => {
  return request.put<ApiResponse>(`/system/menu/${id}`, data)
}

/**
 * 删除菜单
 */
export const deleteMenu = (id: string) => {
  return request.delete<ApiResponse>(`/system/menu/${id}`)
}

/**
 * 获取菜单树结构
 */
export const getMenuTree = (params?: {
  status?: number
  type?: number
}) => {
  return request.get<ApiResponse<Menu[]>>('/system/menu/tree', { params })
}

/**
 * 获取用户菜单
 */
export const getUserMenus = () => {
  return request.get<ApiResponse<Menu[]>>('/system/menu/userMenus')
}

/**
 * 获取菜单选择器数据
 */
export const getMenuSelectTree = (params?: {
  excludeId?: string
}) => {
  return request.get<ApiResponse<Menu[]>>('/system/menu/selectTree', { params })
}